<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup">
  <lv-form-item *ngIf="!isDrill">
    <lv-form-label lvRequired>
      {{ 'protection_restore_to_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group formControlName="restoreLocation">
        <lv-group [lvGutter]="'24px'">
          <lv-radio
            [lvValue]="restoreLocationType.ORIGIN"
            [lvDisabled]="rowCopy?.resource_status === 'NOT_EXIST'"
          >
            {{ 'common_restore_to_origin_location_label' | i18n }}
          </lv-radio>
          <lv-radio [lvValue]="restoreLocationType.NEW">
            {{ 'common_restore_to_new_location_label' | i18n }}
          </lv-radio>
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <ng-container
    *ngIf="formGroup.get('restoreLocation').value === restoreLocationType.ORIGIN"
  >
    <lv-form-item>
      <lv-form-label>
        {{ 'common_location_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <input lv-input type="text" formControlName="originLocation" />
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container
    *ngIf="formGroup.get('restoreLocation').value === restoreLocationType.NEW"
  >
    <aui-select-tag [formGroup]="formGroup" (updateTable)="updateTable($event)" [targetKey]="'target'"></aui-select-tag>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'common_resource_label' | i18n }}
      </lv-form-label>
      <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
        <lv-select
          [lvOptions]="targetOptions"
          formControlName="target"
          lvValueKey="value"
          lvMode="single"
          lvShowFilter
          lvShowCheckAll
          lvFilterKey="label"
          lvFilterMode="contains"
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
<div class="collapse-header">
    <lv-collapse [lvMultiExpansion]="false" lvType="simple">
      <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
        <lv-form-item>
          <lv-form-label>{{'protection_channel_number_label' | i18n}}</lv-form-label>
          <lv-form-control>
            <lv-group lvGutter='8px' class="channel-container">
              <lv-switch formControlName='numberOfChannelOpen'></lv-switch>
              <ng-container *ngIf="formGroup.get('numberOfChannelOpen').value">
                <lv-form-control [lvErrorTip]='numberOfChannelRangeErrorTip'>
                  <input lv-input formControlName="numberOfChannels" type="text" placeholder="1~254"/>
                </lv-form-control>
              </ng-container>
            </lv-group>
          </lv-form-control>
        </lv-form-item>
      </lv-collapse-panel>
    </lv-collapse>
</div>
</lv-form>

<ng-template #titleTpl>
  <lv-group lvGutter='8px'>
    <span class="aui-h3">{{'common_advanced_label'|i18n}}</span>
  </lv-group>
</ng-template>
